$(function() {
	//随机数函数
	function randomNum(x, y) {
		return parseInt(Math.random() * (y - x + 1) + x)
	}
	var timeNum = 10;
	var clickNum = 0;
	//四个验证码
	var one;
	var two;
	var three;
	var four;
	var codeNum = [];
	var codeNum2;
	function timeShow() {
		var time = setInterval(function() {
			timeNum--;
			$(".a_btn1").html("倒计时" + timeNum + "s")
			if(timeNum <= 0) {
				timeNum = 10;
				clickNum = 0;
				clearInterval(time);
				$(".a_btn1").html("获取验证码")
			}

		}, 1000)
	}
	$(".a_btn1").click(function() {
		var phone = $(".a_box1").val().length;
		if(phone != 11) {
			alert("手机格式不正确请重新输入")
		} else {
			var arr = $(".a_box1").val();
			//				var reg = /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
			var reg = /^(1)[3|5|8]\d{9}$/
			if(reg.test(arr) == false) {
				alert("请输入正确的手机号码");
				return;
			} else {
				clickNum++;
				if(clickNum == 1) {
					timeShow();
					$(".c_code").show();
					one=randomNum(0, 9);
					two=randomNum(0, 9);
					three=randomNum(0, 9);
					four=randomNum(0, 9);
					codeNum = [one,two,three,four];
					//验证码为 one two three four
					$(".c_codeCon>i").html(one+ " " + two + " " + three + " " + four);
					$(".a_btn3").on("touchend",function(){
						codeNum2 = $(".a_box2").val().split("");
						for(var i = 0; i <codeNum.length; i++){
							if(codeNum[i] != codeNum2[i]){
//								alert("请输入正确的验证码!!!");
//								window.location.href = "reg.html";
//								$(".c_code").show()
								setTimeout($(".c_code").show(),3000)
								return;
							}else{
								window.location.href = "load.html";
							}
						}
						
					})
					$(".c_close>i").on("click", function() {
						$(".c_code").css("display", "none");
					})
				} else {
					window.confirm("请勿重复获取")
				}
			}
		}

	})
})